/**
 * @description cookie 封装
 * @author LI
 * @date 2020-11-18 14:49
 */
import Cookies from 'js-cookie'

export const cookies = {
  /**
   * @description 存储 cookie 值
   * @param {String} name cookie name
   * @param {String} value cookie value
   * @param {Object} setting cookie setting
   */
  set: (name = 'default', value = '', cookieSetting = {}) => {
    // 设置 cookie 过期时间 为 60 分钟 1 / 24
    const expiresTime = 1
    const currentCookieSetting = {
      expires: expiresTime
    }
    Object.assign(currentCookieSetting, cookieSetting)
    Cookies.set(`li-${name}`, value, currentCookieSetting)
  },

  /**
   * @description 拿到 cookie 值
   * @param {String} name cookie name
   */
  get: (name = 'default') => {
    return Cookies.get(`li-${name}`)
  },

  /**
   * @description 拿到 cookie 全部的值
   */
  getAll: () => {
    return Cookies.get()
  },

  remove: (name = 'default') => {
    return Cookies.remove(`li-${name}`)
  }
}
